package com.qzsoft.zhjd.collect.modules.disconnectInfo.controller;


import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.qzsoft.zhjd.collect.modules.disconnectInfo.service.NSiteDisconnectRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/disconnectInfoCollect")
public class DisconnectInfoController {
    /**
     * 注入Service层
     */
    @Autowired
    private NSiteDisconnectRecordService service;

    /**
     * 断网监测数据上传*（关机或开机操作触发调用发送信息接口）
     */
    @PostMapping("/dataUpload")
    public String dataUpload(@RequestBody JSONArray jsonArray){
        //用以存储插入成功的组信息代码
        String message= null;
        JSONObject result = new JSONObject();
        try {
            message = service.saveDataUpload(jsonArray);
            result.put("code", 200);
            result.put("data",message);
        } catch (Exception e) {
            result.put("code", 300);
        }
        return result.toJSONString();
    }

    /**
     * 在线设备断网监测数据上传*（开机状态定时接收发送信息接口）
     */
    @PostMapping("/onlineDataUpload")
    public String onlineDataUpload(@RequestBody JSONObject jsonObject){
        //用以存储插入成功的组信息代码
        String message= null;
        JSONObject result = new JSONObject();
        try {
            message = service.onlineDataUpload(jsonObject);
            result.put("code", 200);
            result.put("data",message);
        } catch (Exception e) {
            result.put("code", 300);
        }
        return result.toJSONString();
    }

}
